iterate through 2 strings python

44

# Python 3
for f, b in zip(foo, bar):
    print(f, b)

# Python 2
import itertools
for f, b in itertools.izip(foo, bar):
    print(f,b)
    
# zip and izip stop when the shorter of foo or bar stops.
mystring = "Hello Oraask"

# Getting length of string 
lengthOfmystring = len(mystring)

# Iterating through the string using while loop 
for i in mystring[0:lengthOfmystring:2] : 
# Print all characters iterated
    print("Element of string:" , i)

Comments

Submit
0 Comments